package com.lineage.server.command.executor;

import com.lineage.server.datatables.lock.AccountReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Account;
import com.lineage.server.world.World;
import java.util.StringTokenizer;

public class L1ChangPassword implements L1CommandExecutor {
  public static L1CommandExecutor getInstance() {
    return new L1ChangPassword();
  }
  
  public void execute(L1PcInstance pc, String cmdName, String arg) {
    try {
      StringTokenizer st = new StringTokenizer(arg);
      String name = st.nextToken();
      String password = st.nextToken();
      L1PcInstance target = World.get().getPlayer(name);
      String newPassword = "";
      newPassword = password;
      if (target != null) {
        L1Account acc = target.getNetConnection().getAccount();
        acc.set_password(newPassword);
        AccountReading.get().updatePwd(acc.get_login(), newPassword);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("玩家【" + target.getName() + "】的密码以被修改为【" + password + "】"));
        target.sendPackets((ServerBasePacket)new S_SystemMessage("你的密码以被修改GM为【" + password + "】"));
      } else {
        pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(String.valueOf(name)) + "不在线上。"));
      } 
    } catch (Exception e) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage(String.valueOf(String.valueOf(cmdName)) + " 请输入玩家名称 密码 ←请输入。"));
    } 
  }
}
